//
//  AddMemberViewController.m
//  NuwaRobot
//
//  Created by Kendama on 2017/12/4.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "AddMemberViewController.h"
#import "AddUserApi.h"

@interface AddMemberViewController ()

@property(nonatomic,strong) UITextField *phoneTF;
@property(nonatomic,strong) UIButton *shareButton;

@end

@implementation AddMemberViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


#pragma mark --- 点击事件
- (void)didClickShareButton
{
    if (![self.phoneTF.text isMobileNumber])
    {
        [SVProgressHUD showErrorWithStatus:@"请输入正确的手机号码.."];
        return;
    }
    
    AddUserApi *api = [[AddUserApi alloc] initWithDic:@{@"device_id":EXRACT_OBJECT(DEVICEID),@"mobile":self.phoneTF.text}];
    [api dtDefaultInterceptStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        [SVProgressHUD showSuccessWithStatus:[request responseJSONObject][@"errmsg"]];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.navigationController popViewControllerAnimated:YES];
        });
    } failure:nil];
    
}


#pragma mark --- 懒加载
- (UITextField *)phoneTF
{
    if(!_phoneTF)
    {
        UIView *superView = self.view;
        _phoneTF = [[UITextField alloc]init];
        [superView addSubview:_phoneTF];
        _phoneTF.textColor = [UIColor whiteColor];
        _phoneTF.placeholder = @"请输入手机号码";
        _phoneTF.keyboardType = UIKeyboardTypeNumberPad;
        [_phoneTF setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
        
    }
    return _phoneTF;
}

- (UIButton *)shareButton
{
    if(!_shareButton)
    {
        UIView *superView = self.view;
        _shareButton = [[UIButton alloc]init];
        [superView addSubview:_shareButton];
        [_shareButton setTitle:@"添加" forState:UIControlStateNormal];
        [_shareButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_shareButton.titleLabel setFont:fontCommonSize];
        [_shareButton setBackgroundColor:rgba(0,159,236,1)];
        _shareButton.layer.cornerRadius = 5;
        [_shareButton addTarget:self action:@selector(didClickShareButton) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _shareButton;
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.view;

    UILabel *nameLabel = ({
        nameLabel = [[UILabel alloc] init];
        [superView addSubview:nameLabel];
        nameLabel.text = @"分享手机号码";
        nameLabel.font = fontWithSize(16);
        nameLabel.textColor = [UIColor whiteColor];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(271));
            make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(40));
            make.right.mas_equalTo(superView.mas_right).with.offset(-px1080Width(40));
        }];
        nameLabel;
    });
    
    [self.phoneTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nameLabel.mas_bottom).with.offset(px1920Height(52));
        make.left.right.mas_equalTo(nameLabel);
    }];
    
    UIView *lineView = ({
        lineView = [[UIView alloc]init];
        [superView addSubview:lineView];
        lineView.backgroundColor = rgba(27,44,81,1);
        [lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.phoneTF.mas_bottom).with.offset(px1920Height(30));
            make.left.right.mas_equalTo(nameLabel);
            make.height.mas_equalTo(1);
        }];
        lineView;
    });
    
    [self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom).with.offset(px1920Height(150));
        make.left.right.mas_equalTo(lineView);
        make.height.mas_equalTo(px1920Height(136));
    }];
    
    
    UILabel *label = ({
        label = [[UILabel alloc] init];
        [superView addSubview:label];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"您可以将该设备的控制权限分享给您的家人或朋友,被分享的人就可以控制此设备";
        label.font = fontWithSize(14);
        label.textColor = rgba(251,74,79,1);
        label.numberOfLines = 0;
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.shareButton.mas_bottom).with.offset(px1920Height(42));
            make.left.right.mas_equalTo(lineView);
        }];
        nameLabel;
    });
    
}


- (void)setNavigationStyle
{
    [self setNavigationBarTitle:@"添加成员"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
